package D12_6z.反射_5;

import org.apache.commons.io.FileUtils;

import java.io.File;
import java.util.ArrayList;
import java.util.HashMap;
import java.util.List;
import java.util.Map;

public class Demo1 {
    static List<Person> arr = new ArrayList<>();
    public static void main(String[] args) throws Exception {
        HashMap<String,String> map = new HashMap<>();
        List<String> strings = FileUtils.readLines(new File("src/Y2019/M12_/D12_6z/反射_5/data1.txt"));
        for (int i = 0; i < strings.size(); i++) {
            String[] split = strings.get(i).split("=");
            map.put(split[0],split[1]);
        }
        run1(map);
        System.out.println(arr);
    }
    public static void run1(HashMap<String,String> map) throws Exception{
        List<String> strings = FileUtils.readLines(new File("src/Y2019/M12_/D12_6z/反射_5/data2.txt"));
        for (int i = 0; i < strings.size(); i++) {
            String[] s = strings.get(i).split(" ");
            for (Map.Entry<String, String> entry : map.entrySet()) {
                s[0] = s[0].replace("<", "");
                if (entry.getKey().equals(s[0])){
                    Class<?> aClass = Class.forName(entry.getValue());
                    Object o = aClass.getDeclaredConstructor(String.class, String.class, int.class).newInstance(s[1].split("“")[1], s[2].split("“")[1], Integer.parseInt(s[3].split("“")[1].split("”")[0]));
                    arr.add((Person) o);
                }
            }
        }
    }
}
